package com.itheima.info.manager.dao;

import com.itheima.info.manager.domain.Student;

public class StudentDao {
    static Student[] stu = new Student[5];

    public Student[] findStudent() {
        return stu;
    }

    public boolean addStudent(Student stu1) {
        int index = -1;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i]==null){
                index = i;
                break;
            }
        }
        if (index !=-1 ){
            stu[index] = stu1;
            return true;
        }else {
            return false;
        }
    }

    public void deleteStudent(String delId) {
        //获取索引
        stu[getIndex(delId)]=null;
    }
    public int getIndex(String id){
        int index = -1;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i]!=null&&stu[i].getId().equals(id)){
                index = i;
                break;
            }
        }
        return index;
    }

    public void updataStudent(String updataId, Student stu1) {
        stu[getIndex(updataId)] = stu1;
    }
}
